<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0" xmlns:fo="http://www.w3.org/1999/XSL/Format"
   xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" indent="yes"/>

<xsl:template match="doc">
   <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
      <fo:layout-master-set>
         <fo:simple-page-master  margin="0mm 0mm 0mm 0mm" 
           master-name="PageMaster-Cover" page-height="297mm"
           page-width="210mm">
                <fo:region-body  margin="0mm 0mm 0mm 0mm"/>
         </fo:simple-page-master>
         <fo:simple-page-master margin="15mm 25mm 15mm 25mm"  
          master-name="PageMaster-TOC"> page-height="297mm"
           page-width="210mm">
                <fo:region-body color="#333333" margin="0mm 0mm 0mm 0mm"/>
         </fo:simple-page-master>
         <fo:simple-page-master page-height="297mm" page-width="210mm"
             margin="0mm 25mm 20mm 25mm" master-name="PageMaster-Text">
             <fo:region-body margin="15mm 0mm 15mm 0mm"/>
             <fo:region-after region-name="Footer" extent="0.2in"
				precedence="true" color="#333333"/>
         </fo:simple-page-master>
      </fo:layout-master-set>
      <fo:page-sequence master-reference="PageMaster-Cover">
         <fo:flow flow-name="xsl-region-body" color="#333333">
      		 <!--fo:block color="grey" font-size="16">
			      <xsl:value-of select="head/company"/>				 
      		 </fo:block-->
      		 <fo:block margin-top="25mm" margin-left="25mm">
				<xsl:variable name="fileName">
            	 	<xsl:value-of select="head/logo"/>
               </xsl:variable>
        			<fo:external-graphic content-height="scale-to-fit" width="24%" 
        				scaling="uniform" src="{$fileName}"/>								
  			 </fo:block>
             <fo:block color="#2d3373" font-size="24" space-after="12pt" space-before="57mm"
                       margin-left="25mm" margin-right="25mm">
                  <xsl:value-of select="head/employee"/>
             </fo:block>
             <fo:block color="#333333" font-size="16" space-after="12pt"
             		   margin-left="25mm" margin-right="25mm">
                  <xsl:value-of select="head/doc_title"/>
             </fo:block>
             <fo:block color="#666666" font-size="12" space-after="12pt" margin-left="25mm" margin-right="25mm">
                  Date Completed:&#160;
                  <xsl:value-of select="head/date"/>
             </fo:block>
	     <!--Uncomment below if Company name should appear (in addition perhaps to logo-->
             <!--fo:block color="#666666" font-size="12" space-after="12pt" margin-left="25mm" margin-right="25mm">
             	  <xsl:value-of select="head/company"/>
             </fo:block-->
             <fo:block>
                   <xsl:apply-templates select="head/image"/>
             </fo:block>
         </fo:flow>
      </fo:page-sequence>
      <fo:page-sequence master-reference="PageMaster-TOC">
         <fo:flow flow-name="xsl-region-body" color="#333333">
             <fo:block font-weight="bold" color="#2d3373" font-family="Arial,sans-serif" space-after="12pt">
                   CONTENTS
             </fo:block>
             <xsl:for-each select="//chapter|//test">
             	 <xsl:if test="name()='chapter'">
	                 <fo:block text-align-last="justify" font-family="Arial,sans-serif" space-after="6pt">
    	                 <xsl:value-of select="chapter_title"/>
    	                 <fo:leader leader-pattern="dots"/>
    	                 <fo:page-number-citation ref-id="{generate-id()}"/>
        	         </fo:block>
        	     </xsl:if>
        	     <xsl:if test="name()='test'">
	                 <fo:block text-align-last="justify" font-family="Arial,sans-serif" 
	                  space-after="6pt" text-indent="0.25cm" font-size="10pt">
        	             <xsl:value-of select="test_title"/>
            	         <fo:leader leader-pattern="dots"/>
                	     <fo:page-number-citation ref-id="{generate-id()}"/>
                	 </fo:block>
                </xsl:if>                       
             </xsl:for-each>         
      </fo:flow>
      </fo:page-sequence>
      <fo:page-sequence master-reference="PageMaster-Text">
         <fo:static-content flow-name="Footer" font-size="10pt" text-align="center" color="#333333" >
              <fo:block space-before.precedence="force" space-before="24pt">
                  <fo:page-number/>&#160;out of&#160;<fo:page-number-citation ref-id="last-page"/>
              </fo:block>
         </fo:static-content>
         <fo:flow flow-name="xsl-region-body" color="#333333">

            <!--fo:block font-family="Arial,sans-serif">
               <xsl:apply-templates select="//chapter"/>
            </fo:block-->



            <fo:block font-family="Arial,sans-serif">
               <xsl:apply-templates select="//chapter"/>
            </fo:block>

          <fo:block id="last-page"/>
        </fo:flow>
      </fo:page-sequence>
    </fo:root>
</xsl:template>



<xsl:template match="chapter">
   <fo:block break-before="page" id="{generate-id(.)}" color="#333333">
     <xsl:if test="@display-title='yes'">
         <xsl:apply-templates select="chapter_title"/>
     </xsl:if>
     <xsl:if test="chapter_title='Overview'">

     </xsl:if>
     <xsl:apply-templates select="results_table"/>
     <xsl:apply-templates select="image"/>
     <xsl:apply-templates select="p"/>
     <xsl:apply-templates select="h3"/>
     <xsl:apply-templates select="pTest"/>
     <xsl:apply-templates select="test"/>
   </fo:block>   
</xsl:template>

<xsl:template match="results_table">
	            <fo:block>
			<fo:table>

			<fo:table-column column-width="25%"/>
			<fo:table-column column-width="75%"/>

			<fo:table-body>
    				<xsl:for-each select="//test">

	  			<fo:table-row>

   				<fo:table-cell display-align="center">
	      				<fo:block font-size="8pt" color="#2d3373" font-family="Arial,sans-serif">
	      				<xsl:value-of select="test_title"/>
	      				</fo:block>
	    			</fo:table-cell>
      
        			<fo:table-cell text-align="left" display-align="center">
      					<fo:block>
      					<xsl:variable name="fileName"><xsl:value-of select="imageOverview"/></xsl:variable>
			      		<fo:external-graphic content-height="scale-to-fit" width="60%" 
        						scaling="uniform" src="{$fileName}"/>		
      					</fo:block>
    				</fo:table-cell>
  				
				</fo:table-row>
				</xsl:for-each>
		     </fo:table-body>

		</fo:table>
		<xsl:apply-templates/>
            </fo:block>
</xsl:template>

<xsl:template match="chapter_title">
   <fo:block font-weight="bold" space-after="12pt" color="#2d3373"
    keep-with-next="always">
     <xsl:apply-templates/>
   </fo:block>
</xsl:template>

<xsl:template match="p">
   <fo:block space-after="12pt" text-align="justify">
     <xsl:apply-templates />
   </fo:block>   
</xsl:template>

<xsl:template match="pTest">
   <fo:block space-after="12pt" text-align="justify">
	<xsl:apply-templates select="subP" />
   </fo:block>   
</xsl:template>

<xsl:template match="subP">
   <xsl:choose>
  	<xsl:when test="@format='bold'">
	    <fo:inline font-weight="bold">
	    <xsl:apply-templates />
	    <xsl:text>&#160;</xsl:text>
	    </fo:inline>
  	</xsl:when>
  	<xsl:when test="@format='italics'">
	    <fo:inline font-style="italic">
	    <xsl:apply-templates />
	    <xsl:text>&#160;</xsl:text>
	    </fo:inline>
  	</xsl:when>
  	<xsl:when test="@format='bold_and_italics'">
	    <fo:inline font-weight="bold" font-style="italic">
	    <xsl:apply-templates />
	    <xsl:text>&#160;</xsl:text>
	    </fo:inline>
  	</xsl:when>
	<xsl:otherwise>
	    <fo:inline>
	    <xsl:apply-templates />
	    <xsl:text>&#160;</xsl:text>
	    </fo:inline>
	</xsl:otherwise>
   </xsl:choose>
</xsl:template>

<!--xsl:template match="none">
   <fo:block>
     <xsl:apply-templates />
   </fo:block>   
</xsl:template>

<xsl:template match="bold">
   <fo:block font-weight="bold">
     <xsl:apply-templates />
   </fo:block>   
</xsl:template>

<xsl:template match="italics">
   <fo:block font-style="italic">
     <xsl:apply-templates />
   </fo:block>   
</xsl:template>

<xsl:template match="bold_and_italics">
   <fo:block font-weight="bold" font-style="italic">
     <xsl:apply-templates />
   </fo:block>   
</xsl:template-->


<xsl:template match="h3">
   <fo:block font-weight="bold" space-after="0pt" space-before="18pt" text-align="justify" color="#2d3373">
     <xsl:apply-templates/>
   </fo:block>   
</xsl:template>

<xsl:template match="test">
   <fo:block space-after="0pt" space-before="24pt" break-before="page" color="#2d3373"
    font-weight="bold" keep-with-next="always" id="{generate-id(.)}">    
      <xsl:value-of select="test_title"/>
   </fo:block>
   <fo:block space-after="12pt" keep-with-next="always">
      <xsl:value-of select="short_description"/>
   </fo:block>
   <fo:block color="#2d3373" font-weight="bold" keep-with-next="always">
    Score
    </fo:block>
   <xsl:apply-templates select="image"/>
   <xsl:apply-templates select="scores"/>
   <!--xsl:apply-templates select="long_description"/-->
   <xsl:apply-templates select="pTest|h3" />
   <xsl:apply-templates select="p"/>
</xsl:template>


<xsl:template match="image">
     <xsl:variable name="fileName"><xsl:value-of select="."/></xsl:variable>
     <xsl:variable name="zoom"><xsl:value-of select="@zoom-ratio"/></xsl:variable>
     <xsl:choose>
	    <xsl:when test="@zoom-ratio">
		     <fo:block space-after="0pt" text-align="left">
        		 <fo:external-graphic width="{$zoom}" content-height="scale-to-fit"  
          			scaling="uniform" src="{$fileName}"/>
     		 </fo:block>
     	</xsl:when>
     	<xsl:otherwise>
		     <fo:block space-after="0pt" text-align="left">
        		 <fo:external-graphic width="100%" content-height="scale-to-fit"  
          			scaling="uniform" src="{$fileName}"/>
     		 </fo:block>
     	</xsl:otherwise>
     </xsl:choose>
 </xsl:template>     

<xsl:template match="scores">
   <xsl:if test="Max_Score">
	    <fo:block space-before="3pt" space-after="3pt" keep-with-next="always">
		<xsl:text>Maximum possible score is </xsl:text>
                <xsl:value-of select="Max_Score"/>
            </fo:block>
  </xsl:if>    
   <xsl:if test="Raw_Score">
	    <fo:block space-before="3pt" space-after="3pt" keep-with-next="always">
		<xsl:text>Raw score is </xsl:text>
                <xsl:value-of select="Raw_Score"/>
            </fo:block>
  </xsl:if>    
   <xsl:if test="Percentage">
	    <fo:block space-before="3pt" space-after="3pt" keep-with-next="always">
		<xsl:text>Percentage score is </xsl:text>
                <xsl:value-of select="Percentage"/>				      
            </fo:block>
  </xsl:if>
   <xsl:if test="ZScore">
	    <fo:block space-before="3pt" space-after="3pt" keep-with-next="always">
		<xsl:text>Z score is </xsl:text>
                <xsl:value-of select="ZScore"/>
            </fo:block>
  </xsl:if>        
   <xsl:if test="Percentile_Rank">
	    <fo:block space-before="3pt" space-after="3pt" keep-with-next="always">
		<xsl:text>Percentile score is </xsl:text>
                <xsl:value-of select="Percentile_Rank"/>
            </fo:block>
  </xsl:if>    
   <xsl:if test="Sten_Score">
	    <fo:block  space-before="3pt" space-after="3pt" keep-with-next="always">
		<xsl:text>Sten score is </xsl:text>
                <xsl:value-of select="Sten_Score"/>
            </fo:block>
  </xsl:if>
   <xsl:if test="ThetaEAP">
	    <fo:block  space-before="3pt" space-after="3pt" keep-with-next="always">
		<xsl:text>Ability Estimate based on EAP is </xsl:text>
                <xsl:value-of select="ThetaEAP"/>
            </fo:block>
  </xsl:if> 
   <xsl:if test="ThetaML">
	    <fo:block  space-before="3pt" space-after="3pt" keep-with-next="always">
		<xsl:text>Ability Estimate based on MLE is </xsl:text>
                <xsl:value-of select="ThetaML"/>
            </fo:block>
  </xsl:if> 
   <xsl:if test="ThetaMAP">
	    <fo:block  space-before="3pt" space-after="3pt" keep-with-next="always">
		<xsl:text>Ability Estimate based on MAP is </xsl:text>
                <xsl:value-of select="ThetaMAP"/>
            </fo:block>
  </xsl:if> 
   <xsl:if test="ErrorEAP">
	    <fo:block  space-before="3pt" space-after="3pt" keep-with-next="always">
		<xsl:text>Error for EAP is </xsl:text>
                <xsl:value-of select="ErrorEAP"/>
            </fo:block>
  </xsl:if>      
   <xsl:if test="ErrorML">
	    <fo:block  space-before="3pt" space-after="3pt" keep-with-next="always">
		<xsl:text>Error for MLE is </xsl:text>
                <xsl:value-of select="ErrorML"/>
            </fo:block>
  </xsl:if> 
   <xsl:if test="ErrorMAP">
	    <fo:block  space-before="3pt" space-after="3pt" keep-with-next="always">
		<xsl:text>Error for MAP is </xsl:text>
                <xsl:value-of select="ErrorMAP"/>
            </fo:block>
  </xsl:if>           
</xsl:template>

</xsl:stylesheet >

